package cate.game.play.skill.passive.furniture;

import cate.common.table.d.GDAttr;
import cate.common.util.XT;
import cate.game.attr.FightAttr;
import cate.game.play.buff.BuffParam;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.List;

/**
 * 伤害技能降低目标1*施法者pk减伤和0.5*施法者伤害减免，
 * 辅助技能提升目标1*施法者pk加伤和0.5*施法者伤害加深，持续2回合，
 * 坦克和辅助专属技能且只会对战士和法师职业生效，不可叠加，每回合最多2名，冷却4回合
 */
public class 战法激励PH extends PassiveHandler {

	private List<Byte> 生效职业;

	private List<Byte> 目标职业;

	private int 伤害buff;

	private int 辅助buff;

	//生效职业=3#4&目标职业=1#2&
	//伤害buff=？？&辅助buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		生效职业 = args.getByteList("生效职业");
		目标职业 = args.getByteList("目标职业");
		伤害buff = args.getInt("伤害buff", 0);
		辅助buff = args.getInt("辅助buff", 0);
	}

	@Override
	public void onSkillDone(SkillActionCtx action) {
		if (XT.isNotBlank(生效职业) && !生效职业.contains(skill.owner.getJob())) {
			return;
		}
		int buff;

		FightAttr attr = new FightAttr();
		if (action.getSkill().cfg.isHurtSkill()) {
			buff = 伤害buff;
			attr.add(GDAttr.PVP_DOWN, -skill.owner.attr.getTotalValue(GDAttr.PVP_DOWN));
			attr.add(GDAttr.HURT_IGN, -0.5 * skill.owner.attr.getTotalValue(GDAttr.HURT_IGN));
		} else if(action.getSkill().cfg.isSupportSkill()) {
			buff = 辅助buff;
			attr.add(GDAttr.PVP_UP, skill.owner.attr.getTotalValue(GDAttr.PVP_UP));
			attr.add(GDAttr.DAMAGE_ADD, 0.5 * skill.owner.attr.getTotalValue(GDAttr.DAMAGE_ADD));
		}else {
			return;
		}
		BuffParam buffParam = new BuffParam().attrSet(attr);
		for (Fighter target : action.getTargets()) {
			if (XT.isNotBlank(目标职业) && !目标职业.contains(target.getJob())) {
				continue;
			}
			target.buff.tryAddByTid(action, skill.owner, buff, buffParam);
		}
	}
}
